﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
//using System.Data.OracleClient;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Oracle.ManagedDataAccess.Client;
using System.Xml;
using System.Drawing;

/// <summary>
/// DatabaseOperation 的摘要说明
/// </summary>
public class DatabaseOperation
{
    Dbcom cm;
    public DatabaseOperation(Dbcom CM)
    {
        //
        // TODO: 在此处添加构造函数逻辑
        // 
        cm = CM;
    }

    /// <summary>
    /// 获取科室
    /// </summary>
    /// <returns></returns>
    public DataSet GetAllSection()
    {
        string sql_Section = "select sid,section_name from t_sectioninfo where enable_flag='Y'";
        DataSet ds_section = Dbcom.GetDataSet(sql_Section);
        return ds_section;
    }


    public DataSet GetDataSetByType(string dtype)
    {
        string sql = "";
        if (dtype == "0")
        {
            //国籍
            sql = "select code,name from t_data_code t where t.type=130 order by case  when t.name='中国' then 0 else 1 end,code";
        }
        else if (dtype == "1")
        {
            //付款方式
            sql = "select * from t_data_code where type=70 order by id asc";
        }
        else if (dtype == "2")
        {
            //省份
            sql="select name, code as id from t_data_code where type = 185 and enable = 'Y' "+
                "and code between 35 and 68 order by order_id,code";
        }
        else if (dtype == "3")
        {
            //病人关系
            sql = "select id,name,code from t_data_code where type='131'";
        }
        else if (dtype == "4")
        {
            //职业
            sql = "select id,code,name from t_data_code where type='134'";
        }
        else if (dtype == "5")
        {
            //民族
            sql = "select code,name from t_data_code where type='71' and enable='Y' order by case  when name='汉族' then 0 else 1 end,code";
        }
        else if (dtype == "6")
        {
            //护理等级
            sql = @"select a.id,a.name from t_data_code a inner join t_data_code_type b 
                                        on a.type = b.id where b.name = '护理等级'";
        }
        else if (dtype == "7")
        {
            //婚姻
            sql = "select id,name,code from t_data_code where type='112' and enable='Y'";
        }

        if (sql != "")
            return Dbcom.GetDataSet(sql);
        else
            return null;

    }

    /// <summary>
    /// 根据身份的ID获取 市
    /// </summary>
    /// <returns></returns>
    public DataSet GetCitysByProviceId(string provinceId)
    {
        string select_bzdm = "select bzdm from t_data_code where substr(bzdm,3,4)='0000' and code='" + provinceId + "' and type='185'";
        string qydm = Dbcom.ReadSqlVal(select_bzdm, 0, "bzdm");
        string bzdm = qydm.Substring(0, 2);
        string sql = "select id,name from t_data_code" +
                    " where substr(bzdm,0,2)='" + bzdm + "' and substr(bzdm,5,2)='00' and bzdm!='" + qydm + "'order by order_id,bzdm";
        if (bzdm.Contains("11") || bzdm.Contains("12") ||
            bzdm.Contains("31") || bzdm.Contains("50"))//直辖市除外 北京，上海 ，天津
        {
            sql = "select id,name from t_data_code" +
                    " where substr(bzdm,0,2)='" + bzdm + "' and bzdm!='" + qydm + "' order by order_id,bzdm";
        }

        return Dbcom.GetDataSet(sql);
    }



     /// <summary>
     /// 获取定制界面的对象参数
     /// </summary>
     /// <returns></returns>
    public List<FixTypeObject> GetFixTypeObjects()
    {
        List<FixTypeObject> FixTypeObjects = new List<FixTypeObject>();

        #region 参数设置
        FixTypeObject temp1 = new FixTypeObject();
        temp1.Code = "";
        temp1.Name = "";
        FixTypeObjects.Add(temp1);

        FixTypeObject ucDIAGNOSIS_CERTIFICATE = new FixTypeObject();
        ucDIAGNOSIS_CERTIFICATE.Code = "ucDIAGNOSIS_CERTIFICATE";
        ucDIAGNOSIS_CERTIFICATE.Name = "诊断证明";
        FixTypeObjects.Add(ucDIAGNOSIS_CERTIFICATE);

        FixTypeObject ucTemperPrint = new FixTypeObject();
        ucTemperPrint.Code = "ucTemperPrint";
        ucTemperPrint.Name = "体温单打印展示";
        FixTypeObjects.Add(ucTemperPrint);

        FixTypeObject frmCases_First = new FixTypeObject();
        frmCases_First.Code = "frmCases_First";
        frmCases_First.Name = "首页";
        FixTypeObjects.Add(frmCases_First);
        //袁杨添加 中医首页
        FixTypeObject frmCases_Firstx = new FixTypeObject();
        frmCases_First.Code = "frmCases_Firstx";
        frmCases_First.Name = "中医首页";
        FixTypeObjects.Add(frmCases_Firstx);


        FixTypeObject ucfrmSickReport = new FixTypeObject();
        ucfrmSickReport.Code = "ucfrmSickReport";
        ucfrmSickReport.Name = "排班设置";
        FixTypeObjects.Add(ucfrmSickReport);

        FixTypeObject UcPatientInfo = new FixTypeObject();
        UcPatientInfo.Code = "UcPatientInfo";
        UcPatientInfo.Name = "病人基本信息";
        FixTypeObjects.Add(UcPatientInfo);

        FixTypeObject UOdinopoeia_Record = new FixTypeObject();
        UOdinopoeia_Record.Code = "UOdinopoeia_Record";
        UOdinopoeia_Record.Name = "中期妊娠引产产后病程记录";
        FixTypeObjects.Add(UOdinopoeia_Record);

        FixTypeObject ExpectantRecord = new FixTypeObject();
        ExpectantRecord.Code = "ExpectantRecord";
        ExpectantRecord.Name = "待产记录";
        FixTypeObjects.Add(ExpectantRecord);

        FixTypeObject ucHeart_PIC = new FixTypeObject();
        ucHeart_PIC.Code = "ucHeart_PIC";
        ucHeart_PIC.Name = "心电图";
        FixTypeObjects.Add(ucHeart_PIC);

        FixTypeObject MUcToolsControl = new FixTypeObject();
        MUcToolsControl.Code = "MUcToolsControl";
        MUcToolsControl.Name = "编辑器护理单";
        FixTypeObjects.Add(MUcToolsControl);

        FixTypeObject ucTempraute = new FixTypeObject();
        ucTempraute.Code = "ucTempraute";
        ucTempraute.Name = "体温单";
        FixTypeObjects.Add(ucTempraute);

        FixTypeObject ucPartogram = new FixTypeObject();
        ucPartogram.Code = "ucPartogram";
        ucPartogram.Name = "产程图";
        FixTypeObjects.Add(ucPartogram);
        #endregion

        return FixTypeObjects;
    }
}